<template>
  <view class="integral">
    <navbarIntegral :signInfo="signInfo" />

    <scroll-view class="scroll" scroll-y>
      <!-- 占位 -->
      <view class="placeholder" />

      <view class="task">
        <view class="title-task">积分任务</view>

        <view class="task-item">
          <view class="item-Box" v-for="item in taskList">
            <view class="l">
              <view class="icon">
                <image class="" style="height: 64rpx; width: 64rpx" :src="item.icon"
                  mode="aspectFit|aspectFill|widthFix" />
              </view>

              <text class="name">
                {{ item.taskName }}
              </text>

              <text class="points" selectable="false" space="false" decode="false">
                +{{ item.integralQuantity }}
              </text>
            </view>

            <view class="r finish" v-if="item.status==='2'">
              <text class="text finish">已完成</text>
            </view>
            <view class="r nofinish" v-else @click="handleOperate(item)">
              <text class="text noFinish" selectable="false" space="false" decode="false">
                {{ item.btnName }}
              </text>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import navbarIntegral from "../components/navbarIntegral.vue";
import { getIntegralSign, sign, getIntegralTaskList } from '@/api/pages/mine.js'

export default {
  components: { navbarIntegral },
  data() {
    return {
      signInfo: {},
      taskList: [
        {
          id: 1,
          taskName: "",
          btnName: '去签到',
          integralQuantity: 0,
          status: 0,
          icon: require("../../../../static/images/mIntergral/mr.png"),
        },
        {
          id: 2,
          taskName: "",
          btnName: '去完善',
          integralQuantity: 0,
          status: 1,
          icon: require("../../../../static/images/mIntergral/ws.png"),
        },
        {
          id: 3,
          taskName: "",
          btnName: '去投递',
          integralQuantity: 0,
          status: 1,
          icon: require("../../../../static/images/mIntergral/sc.png"),
        }
      ],
    };
  },
  computed: {},
  // 监控data中的数据变化
  watch: {},
  onLoad(options) { },
  onShow() { },
  onReady() { },
  mounted() {
    this.getIntegralSignFun()
  },
  methods: {
    // 获取积分/签到状态
    getIntegralSignFun() {
      getIntegralSign().then((res) => {
        console.log(res);
        if (res.code === 200) {
          this.taskList[0].status = res.data.status
          this.signInfo = res.data
        }
      })
      getIntegralTaskList().then((res) => {
      if(res.code===200){
        this.taskList=res.data || []
        this.taskList.forEach((e,index)=>{
          if(e.taskName==='每日签到'){
            e.icon='../../../../static/images/mIntergral/mr.png'
            e.btnName='去签到'
          }
          if(e.taskName==='完善简历'){
            e.icon='../../../../static/images/mIntergral/ws.png'
            e.btnName='去完善'
            e.path='/pages/recruit/mine/myResume/index'
          }
          if(e.taskName==='首次投递简历'){
            e.icon='../../../../static/images/mIntergral/sc.png'
            e.btnName='去投递'
            e.path='/pages/tabbarChange/firstPage/index'
          }
        })
      }
      })
    },
    // 去签到/完善简历/投递
    handleOperate(item) {
      if (item.btnName === '去签到') {
        sign().then((res) => {
          if (res.code === 200) {
            uni.showToast({
              title: '签到成功'
            })
            this.getIntegralSignFun()
          }
        })
      }
      if(item.btnName === '去完善'){
        uni.navigateTo({
          url:item.path
        })
      }
      if(item.btnName === '去投递'){
        uni.switchTab({
          url:item.path
        })
      }
    }
  },
};
</script>
<style lang="scss" scoped>
.integral {
  height: 100vh;
  background-color: #f9f9f9;
  overflow: hidden;

  .scroll {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 24rpx;
    overflow: hidden;

    .placeholder {
      height: 415rpx;
    }

    .task {
      display: flex;
      flex-direction: column;
      width: 100%;

      .title-task {
        width: 144rpx;
        height: 50rpx;
        font-family: PingFangSC-Medium;
        font-weight: 500;
        font-size: 36rpx;
        color: #000000e0;
        letter-spacing: 0;
        margin: 32rpx 0;
      }

      .task-item {
        width: 702rpx;
        display: flex;
        flex-direction: column;

        .item-Box {
          height: 142rpx;
          display: flex;
          justify-content: space-between;
          align-items: center;
          background: #ffffff;
          box-shadow: 0 0 12rpx 0 #e2e2e299;
          border-radius: 16rpx;
          padding: 0 24rpx;
          margin-bottom: 24rpx;

          .l {
            display: flex;
            align-items: center;

            .icon {
              width: 64rpx;
              height: 64rpx;
              margin-right: 16rpx;
            }

            .name {
              height: 45rpx;
              font-weight: 600;
              font-size: 32rpx;
              color: #000000e0;
              letter-spacing: 0;
            }

            .points {
              font-size: 28rpx;
              color: #00000073;
              font-weight: 600;
            }
          }

          .nofinish {
            width: 170rpx;
            height: 64rpx;
            background: #ff9e24;
            border-radius: 44rpx;
            display: flex;
            justify-content: center;
            align-items: center;

            .text {
              color: #ffffff;
              font-size: 24rpx;
            }
          }

          .finish {
            width: 170rpx;
            height: 64rpx;
            background: #d8d8d83d;
            border-radius: 44rpx;
            display: flex;
            justify-content: center;
            align-items: center;

            .text {
              color: #000000e0;
              font-size: 24rpx;
            }
          }
        }
      }
    }
  }
}
</style>
